package com.lmx.repoDomain.repository;

import java.util.Iterator;

import javax.annotation.PostConstruct;

import org.springframework.stereotype.Component;

import com.lmx.repoDomain.tmodel.Customer;
import com.lmx.repoDomain.tmodel.CustomerDrugProject;
import com.lmx.repoDomain.tmodel.Dicttype;
import com.lmx.repoDomain.tmodel.Employee;
import com.lmx.repoDomain.tmodel.HbeaconWarning;
import com.lmx.repoDomain.tmodel.NursingPlanDetail;
import com.lmx.repoDomain.tmodel.RecordViolation;

import io.katharsis.queryParams.QueryParams;
import io.katharsis.repository.annotations.JsonApiFindAll;
import io.katharsis.repository.annotations.JsonApiResourceRepository;

@JsonApiResourceRepository(RecordViolation.class)
@Component
public class RecordViolationRepository extends BaseRepository<RecordViolation> {

	@PostConstruct
	public void init() {
		dslJpaService.setEntityClass(RecordViolation.class);
	}
	
	@Override
	@JsonApiFindAll
	public Iterable<RecordViolation> findAll(final QueryParams requestParams) {
		
		Iterable<RecordViolation> dataList = super.findAll(requestParams);
		Iterator it = dataList.iterator();
		while (it.hasNext()) {
			RecordViolation res = (RecordViolation) it.next();
			Customer customer = res.getCustomer();
			if(customer != null) {
				res.setCustomer(customer);
			}
			CustomerDrugProject customerDrugProject = res.getCustomerDrugProject();
			if(customerDrugProject != null) {
				res.setCustomerDrugProject(customerDrugProject);
			}
			Dicttype type2 = res.getType();
			if(type2 != null) {
				res.setType(type2);
			}
			Employee employee = res.getEmployee();
			if(employee != null) {
				res.setEmployee(employee);
			}
			HbeaconWarning hbeaconWarning = res.getHbeaconWarning();
			if(hbeaconWarning != null) {
				res.setHbeaconWarning(hbeaconWarning);
			}
			NursingPlanDetail nursingPlanDetail = res.getNursingPlanDetail();
			if(nursingPlanDetail != null) {
				res.setNursingPlanDetail(nursingPlanDetail);
			}
		}
		return dataList;
	}

}
